<!DOCTYPE html>
<html>
<head>
    <title>SRS</title>
    <meta charset="utf-8">
    <style>
        body{
			font-size: 14px;
			padding: 0;
			margin: 0;
			background-color: black;
        }
		.holder{
			width: 100%;
			height: 100%;
			position: relative;
		}
		.top-control-box{
			position: absolute;
			top: 0;
			background-color: #838383;
			padding: 10px;
			border-radius: 0 0 10px 10px;
			display: flex;
			align-items: center;
			left: 50%;
			transform: translateX(-50%);
		}
		@keyframes fadeInOut {
		  0% {
		    opacity: 0; /* 初始透明度为0 */
		  }
		  50% {
		    opacity: 1; /* 中间透明度为1 */
		  }
		  100% {
		    opacity: 0; /* 结束透明度为0 */
		  }
		}
		.green-dot{
			background-color: #59e085;
			width: 15px;
			height: 15px;
			border-radius: 50%;
			animation: fadeInOut 2s infinite;
		}
		.exit-box{
			background-color: #ff6060;
			color: white;
			display: flex;
			align-items: center;
			padding: 5px 10px;
			border-radius: 30px;
			margin-left: 20px;
		}
    </style>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="js/adapter-7.4.0.min.js"></script>
    <script type="text/javascript" src="js/srs.sdk.js"></script>
    <script type="text/javascript" src="js/winlin.utility.js"></script>
    <script type="text/javascript" src="js/srs.page.js"></script>
</head>
<body>
<div>
	<div class="holder">
		<video id="rtc_media_player" style="width: 100%;height: 100%;" controls autoplay></video>
		<div class="top-control-box">
			<div class="green-dot"></div>
			<div style="margin-left: 15px;">LIVEING</div>
			<div style="margin-left: 15px;">CHANLE ID/ROOM ID</div>
			<div class="exit-box">
				<div>EXIT</div>
				<img src="images/delete.png" style="width: 15px;height: 15px;margin-left: 5px;"/>
			</div>
		</div>
	</div>
</div>
<img src='//ossrs.net/gif/v1/sls.gif?site=ossrs.net&path=/player/rtcpublisher'/>
<script type="text/javascript">
$(function(){
    var sdk = null; // Global handler to do cleanup when republishing.
    var startPlay = function() {
        $('#rtc_media_player').show();
        if (sdk) {
            sdk.close();
        }
        sdk = new SrsRtcWhipWhepAsync();

        // User should set the stream when publish is done, @see https://webrtc.org/getting-started/media-devices
        // However SRS SDK provides a consist API like https://webrtc.org/getting-started/remote-streams
        $('#rtc_media_player').prop('srcObject', sdk.stream);
        // Optional callback, SDK will add track to stream.
        // sdk.ontrack = function (event) { console.log('Got track', event); sdk.stream.addTrack(event.track); };

        // For example: webrtc://r.ossrs.net/live/livestream
        // var url = $("#txt_url").val();
		 var query = parse_query_string();
		var url = "https://live.panggg.com:443/rtc/v1/whep/?app=live&stream="+query.roomId
        sdk.play(url).then(function(session){
            $('#sessionid').html(session.sessionid);
            $('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
        }).catch(function (reason) {
            sdk.close();
            $('#rtc_media_player').hide();
            console.error(reason);
        });
    };

    $('#rtc_media_player').hide();
    var query = parse_query_string();
	console.log('query: ',query);
    srs_init_whep("#txt_url", query);

    $("#btn_play").click(startPlay);
    if (query.autostart === 'true') {
        $('#rtc_media_player').prop('muted', true);
        window.addEventListener("load", function(){ startPlay(); });
    }
	$(".exit-box").click(() => {
		console.log('query: ',query);
		if (confirm("确定退出当前直播吗?")) {
		    // 用户点击了确定，执行相关操作
			console.log('111: ');
			window.history.back();
		} else {
		    // 用户点击了取消，不执行操作或者执行其他操作
			console.log('222: ');
		}
	})
});
</script>
</body>
</html>

